<?php

class MyModel extends CActiveRecord{

protected function beforeSave()
	{
		if(parent::beforeSave())
		{
			if($this->isNewRecord)
			{
				$this->created_time=date('Y-m-d H:i:s');
				$this->created_by=Yii::app()->user->getId();
				$this->updated_by=Yii::app()->user->getId();
				$this->updated_time=date('Y-m-d H:i:s');
			}
			else
				$this->updated_by=Yii::app()->user->getId();
				$this->updated_time=date('Y-m-d H:i:s');
			return true;
		}
		else
			return false;
	}

}

?>